﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using TDT_Project.classes;
namespace TDT_Project.Controller
{
    public partial class uc_nienche : System.Web.UI.UserControl
    {
        cls_nienkhoa nienche = new cls_nienkhoa();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                load_nienche();
                cls_dungchung.nienkhoa_id_load = ddl_nienkho.SelectedValue.ToString();
                cls_dungchung.nienkhoa_ten_load = ddl_nienkho.SelectedItem.ToString();
            }
        }
        private void load_nienche()
        {
            DataSet ds = nienche.load_nienkho_combo();
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                ddl_nienkho.DataSource = ds;
                ddl_nienkho.DataTextField = "TenNienHoc";
                ddl_nienkho.DataValueField = "NienHoc_id";
                ddl_nienkho.DataBind();
                string s="";
                if (DateTime.Now.Month > 8)
                     s= DateTime.Now.Year + "-" + DateTime.Now.AddYears(1).Year;
                else
                   s = DateTime.Now.AddYears(-1).Year + "-" + DateTime.Now.Year;
                DataRow[] dr = ds.Tables[0].Select("TenNienHoc='" + s + "'");
                if (dr.Count() > 0)
                    ddl_nienkho.SelectedValue = dr[0][0].ToString();
            }
        }

        protected void ddl_nienkho_SelectedIndexChanged(object sender, EventArgs e)
        {
            cls_dungchung.nienkhoa_id_load = ddl_nienkho.SelectedValue.ToString();
            cls_dungchung.nienkhoa_ten_load = ddl_nienkho.SelectedItem.ToString();
        }
    }
}